class Solution
{
public:
    vector<int> replaceElements(vector<int> &arr)
    {
        int leftMax = arr.back();
        arr.back() = -1;
        for (int i = arr.size() - 2; i >= 0; --i)
        {
            int num = arr[i];
            arr[i] = leftMax;
            leftMax = max(leftMax, num);
        }
        return arr;
    }
};